package com.jianjun.project.system.notice;

import com.jfinal.aop.Before;
import com.jfinal.kit.Kv;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Page;
import com.jfinal.plugin.activerecord.SqlPara;
import com.jfinal.plugin.activerecord.tx.Tx;
import com.jianjun.project.common.model.SysNotice;

import java.util.Date;

/**
 * 公告 服务层实现
 *
 * @author source
 */

public class SysNoticeService {
    private final SysNotice dao = new SysNotice().dao();


    public Page<SysNotice> paginate(SysNotice model) {
        SqlPara sqlParaDb = Db.getSqlPara("querySysNotice", Kv.by("cond", model.toMap()).set(model.getColumnAsc()));
        return dao.paginate(model.getPageNum(), model.getPageSize(), sqlParaDb);
    }

    /**
     * 查询公告信息
     *
     * @param noticeId 公告ID
     * @return 公告信息
     */
    public SysNotice selectNoticeById(Long noticeId) {
        return dao.findById(noticeId);
    }


    /**
     * 新增公告
     *
     * @param notice 公告信息
     * @return 结果
     */
    public boolean insertNotice(SysNotice notice) {
        notice.setCreateTime(new Date());
        return notice.save();
    }

    /**
     * 修改公告
     *
     * @param notice 公告信息
     * @return 结果
     */
    public boolean updateNotice(SysNotice notice) {
        notice.setUpdateTime(new Date());
        return notice.update();
    }

    /**
     * 批量删除公告信息
     */
    @Before(Tx.class)
    public boolean deleteNoticeByIds(Long[] ids) {
        for (Long id : ids) {
            dao.deleteById(id);
        }
        return true;
    }


}
